package monster.flight.admin.action.xtgl.role;

import org.apache.struts2.json.annotations.JSON;

import monster.comm.action.BaseJsonAction;
import monster.comm.log.ILog;
import monster.comm.log.LogService;
import monster.comm.util.ReturnConstant;
import monster.flight.admin.manager.service.xtgl.RoleService;
import monster.flight.comm.entity.vo.Xt_role;

/**
 * 
 * 创建信息
 * ============= 类名: monster.flight.admin.action.xtgl.role.RoleCheckAction
 * 类作用描述: * 后台系统管理角色管理字段校验
 * 创建人：fyr 
 * 创建时间： 2013-1-18 上午11:26:10 
 * 修改信息1=============
 * 修改类型: //1.修改bug 2.业务变化修改 修改描述: 修改人： 修改时间：
 */
public class RoleCheckAction extends BaseJsonAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -636681519809823339L;
	private static ILog log = LogService.getLog(RoleCheckAction.class);
	
	private RoleService roleService;
	private Xt_role role ;
	private String fieldId;					//ajax字段校验的字段ID
	private String fieldValue;				//ajax字段校验的字段的值
	/**
	 * 通过角色编号查找角色
	 * 在新增角色的时候进行校验编号是否可用
	 * @return
	 */
	@JSON(serialize=false)
	public String getRoleById(){
		String isLogin = isLogin();
		if("1".equals(isLogin)){
			try {
				role = roleService.getRoleByID(fieldValue);	
				if(role!=null){	
					returnVO.validationReturn = "[\""+fieldId+"\",false]";
				}else{
					returnVO.validationReturn = "[\""+fieldId+"\",true]";
				}
			} catch (Exception e) {
				returnVO.returnCode = ReturnConstant.IS_ERR;
				log.error(e.getMessage(), e);
			}
		}else{
			returnVO.returnCode = ReturnConstant.IS_NOT_LOGIN;
			returnVO.validationReturn="[[\"role_name\",false,\"checkRolecode\"]]";
		}
		
		return SUCCESS;
	}
	/**
	 * 新增form验证
	 * @return
	 */
	public String checkForm(){
		String isLogin = isLogin();
		if("1".equals(isLogin)){
			try {
				role = roleService.getRoleByID(role.getRole_code());	
				
				if(role==null||"".equals(role)){	
					returnVO.validationReturn="[[\"role_code\",true,\"checkRolecode\"]]";
					returnVO.returnCode = ReturnConstant.IS_DEAL_OK;
				}else{
					returnVO.validationReturn="[[\"role_code\",false,\"checkRolecode\"]]";
					returnVO.returnCode = ReturnConstant.IS_DEAL_FAIL;
				}
			} catch (Exception e) {
				returnVO.returnCode = ReturnConstant.IS_ERR;
				returnVO.validationReturn="[[\"role_code\",false,\"checkRolecode\"]]";
				returnVO.returnDesc = e.getMessage();
				log.error(e.getMessage(),e);
			}
		}else{
			returnVO.returnCode = ReturnConstant.IS_NOT_LOGIN;
			returnVO.validationReturn="[[\"role_code\",false,\"checkRolecode\"]]";
		}
		return SUCCESS;
	}
	/**
	 * 修改form验证
	 * @return
	 */
	public String checkFormEdit(){
		String isLogin = isLogin();
		if("1".equals(isLogin)){
			try {
				role = roleService.getRoleByID(role.getRole_code());	
				returnVO.returnCode = ReturnConstant.IS_DEAL_OK;
				if(role==null||"".equals(role)){	
					returnVO.validationReturn="[[\"role_code\",false,null]]";
				}else{
					returnVO.validationReturn="[[\"role_name\",true,null]]";
				}
			} catch (Exception e) {
				returnVO.returnCode = ReturnConstant.IS_ERR;
				returnVO.validationReturn="[[\"role_name\",false,null]]";
				returnVO.returnDesc = e.getMessage();
				log.error(e.getMessage(),e);
			}
		}else{
			returnVO.returnCode = ReturnConstant.IS_NOT_LOGIN;
			returnVO.validationReturn="[[\"role_name\",false,null]]";
		}
		return SUCCESS;
	}
	public Xt_role getRole() {
		return role;
	}
	public void setRole(Xt_role role) {
		this.role = role;
	}
	public String getFieldId() {
		return fieldId;
	}
	public void setFieldId(String fieldId) {
		this.fieldId = fieldId;
	}
	public String getFieldValue() {
		return fieldValue;
	}
	public void setFieldValue(String fieldValue) {
		this.fieldValue = fieldValue;
	}
	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}
	
	
}
